package luyihan;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class Serialization {
    public static void main(String[] args) {
        //创建对象
        User user01 = new User(99,"火锅大王","luyihan12345","123@123.com","060606");

        //序列化操作——存入文件中
        try {
            //创建一个文件 保存后续序列化的数据
            FileOutputStream fileOutputStream = new FileOutputStream("D:\\Desktop\\11.txt");

            //创建序列化工具 将user保存在文件中
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);

            //开始序列化操作
            objectOutputStream.writeObject(user01);

            System.out.println("序列化成功");
            //关闭输出流
            fileOutputStream.close();
            objectOutputStream.close();


        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
